package com.eastfair.venueservice.service.impl;

import com.eastfair.core.base.R;
import com.eastfair.core.exception.BizException;
import com.eastfair.home.api.ReportVenueSpaceFeign;
import com.eastfair.home.dto.ReportVenueSpaceDTO;
import com.eastfair.home.enumeration.ReportVenueSpaceDrawingAuditStatusEnum;
import com.eastfair.home.enumeration.ReportVenueSpaceReportSpaceStatusEnum;
import com.eastfair.venueservice.dto.ReportVenueSpaceAuditDTO;
import com.eastfair.venueservice.entity.ReportVenueSpaceAudit;
import com.eastfair.venueservice.service.VenueManageReportVenueSpaceService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * 一键报馆 服务.
 *
 * @author dqq
 * @date 2022 /9/13
 */
@Service
@Slf4j
public class VenueManageReportVenueSpaceServiceImpl implements VenueManageReportVenueSpaceService {

    @Resource
    private ReportVenueSpaceFeign reportVenueSpaceFeign;

    @Override
    public boolean updateAuditStatus(ReportVenueSpaceDTO reportVenueSpaceDTO) {
        R<Boolean> result = reportVenueSpaceFeign.updateAuditStatus(reportVenueSpaceDTO);
        if (!result.getIsSuccess()) {
            throw BizException.wrap(result.getCode(), result.getMsg());
        }
        return result.getData();
    }

    @Override
    public boolean updateAuditStatus(ReportVenueSpaceAudit reportVenueSpaceAudit) {
        ReportVenueSpaceDTO reportVenueSpaceDTO = new ReportVenueSpaceDTO();
        reportVenueSpaceDTO.setId(reportVenueSpaceAudit.getReportVenueSpaceId());
        reportVenueSpaceDTO.setReportVenueSpaceNumber(reportVenueSpaceAudit.getReportVenueSpaceNumber());
        ReportVenueSpaceDrawingAuditStatusEnum reportVenueSpaceDrawingAudit
                = ReportVenueSpaceDrawingAuditStatusEnum.get(reportVenueSpaceAudit.getDrawingAuditStatus().getCode());
        reportVenueSpaceDTO.setDrawingAuditStatus(reportVenueSpaceDrawingAudit);
        reportVenueSpaceDTO.setDrawingAuditOpinion(reportVenueSpaceAudit.getDrawingAuditOpinion());
        reportVenueSpaceDTO.setDrawingAuditUserId(reportVenueSpaceAudit.getDrawingAuditUserId());
        reportVenueSpaceDTO.setDrawingAuditUserName(reportVenueSpaceAudit.getDrawingAuditUserName());
        ReportVenueSpaceReportSpaceStatusEnum reportVenueSpaceStatus
                = ReportVenueSpaceReportSpaceStatusEnum.get(reportVenueSpaceAudit.getReportSpaceStatus().getCode());
        reportVenueSpaceDTO.setReportSpaceStatus(reportVenueSpaceStatus);
        return updateAuditStatus(reportVenueSpaceDTO);
    }
}